<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Model
 *
 * @author hoangle
 */
class Service_Model {
    //put your code here
    public function __contruct() {}

    /**
     * Factory
     */
    public function factory($class, $method, $arrParams, $module)
    {
        //Get model dir
        $modelDir = Zend_Controller_Action::getFrontController()->getModuleDirectory($module)
                       . DIRECTORY_SEPARATOR . 'models';

        //Load Model
        Zend_Loader::loadClass($class, $modelDir);

        //Init class
        $objClass = new $class();
        try {
        //Exec method
        $result = $objClass->$method($arrParams);
        }
        catch (Zend_Exception $e) {
            self::logFile($e->getMessage());
        }
        return $result;
    }
    
    /**
     * @desc Write log file
     * @param <type> $params
     */
    public function logFile($params) {
        $path = dirname(APPLICATION_PATH) . '/public/logs/database/error_' . date("dmY").'.log';
        $handle = fopen($path, 'a');
        $params  .= "\r\n";
        fwrite($handle, $params);
        fclose($handle);
    }

}
?>
